package com.learn.micro_mall.service.api.coupon.impl;

import com.learn.micro_mall.domain.entity.coupon.CouponEntity;
import com.learn.micro_mall.repository.coupon.CouponRepository;
import com.learn.micro_mall.service.api.coupon.CouponService;
import com.learn.micro_mall.service.convertor.coupon.CouponMapper;
import com.learn.micro_mall.service.request.coupon.CouponCreateRequest;
import com.learn.micro_mall.service.response.coupon.CouponCreateResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/coupon")
public class CouponServiceImpl implements CouponService {

    @Resource
    private CouponRepository couponRepository;


    @Override
    @RequestMapping("/create")
    public CouponCreateResponse createCoupon(CouponCreateRequest request) throws Exception {
        CouponEntity couponEntity = CouponMapper.INSTANCES.toCouponEntity(request);
        couponEntity.valid();
        couponRepository.insert(couponEntity);
        return null;
    }
}
